package com.farmpost.server.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmpost.server.pojo.ReplyComment;
import com.farmpost.server.pojo.RespBean;
import com.farmpost.server.service.IReplyCommentService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 回复表 前端控制器
 * </p>
 *
 * @author king
 * @since 2022-04-08
 */
@RestController
@RequestMapping("/reply")
public class ReplyCommentController {

    @Autowired
    private IReplyCommentService iReplyCommentService;

    @ApiOperation(value = "发表回复")
    @PostMapping("/postReply")
    public RespBean postReply(@RequestBody Map<String, Object> map) {
        return iReplyCommentService.postReply((Integer) map.get("id"), (Integer) map.get("toUid"), (String) map.get("content"), (String) map.get("topicType"));
    }

    @ApiOperation(value = "根据id获取回复并据时间最新查询")
    @GetMapping("/getReplyById")
    public List<ReplyComment> getReplyById(@RequestParam Integer id, @RequestParam String topicType, @RequestParam long currentPage) {
        Page<ReplyComment> page = new Page<>(currentPage,20);
        return iReplyCommentService.getReplyById(id, topicType, page);
    }

    @ApiOperation(value = "查询回复")
    @GetMapping("/queryReply")
    public List<ReplyComment> queryReplyByPage(@RequestBody Map<String, Object> map) {
        String topicType = (String) map.get("topicType");
        Integer id = (Integer) map.get("id");
        if ("comment".equals(topicType)) {
            return iReplyCommentService.queryReplyByTopicId(id);
        }else if ("reply".equals(topicType)) {
            return iReplyCommentService.queryReplyByReplyId(id);
        }
        return null;
    }
}
